/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
<template>
  <m-popover
    ref="popover"
    @ok="_ok"
    @close="close"
  >
    <template slot="content">
      <div class="create-user-model">
        <m-list-box-f>
          <template slot="name"><strong>*</strong>用户组名称</template>
          <template slot="content">
            <el-input
              type="input"
              v-model="form.userGroup"
              maxlength="60"
              size="small"
              placeholder="请输入用户组名称"
            >
            </el-input>
          </template>
        </m-list-box-f>
        <m-list-box-f>
          <template slot="name">备注</template>
          <template slot="content">
            <el-input
              type="textarea"
              :rows="3"
              placeholder="请输入内容"
              v-model="form.remark"
              maxlength="300"
            >
            </el-input>
          </template>
        </m-list-box-f>
        <m-list-box-f>
          <template slot="name">用户组管理员</template>
          <template slot="content">
            <el-select
              v-model="form.userIds"
              placeholder="请选择"
              size="mini"
              style="width: 100%;"
              multiple
              clearable
            >
              <el-option
                v-for="item in options"
                :key="item.value"
                :label="item.label"
                :value="item.value"
              >
              </el-option>
            </el-select>
          </template>
        </m-list-box-f>
        <m-list-box-f>
          <template slot="name">关联资源分组</template>
          <template slot="content">
            <el-select
              v-model="form.resourceIds"
              placeholder="请选择"
              size="mini"
              style="width: 100%;"
              multiple
              clearable
            >
              <el-option
                v-for="item in options"
                :key="item.value"
                :label="item.label"
                :value="item.value"
              >
              </el-option>
            </el-select>
          </template>
        </m-list-box-f>
        <m-list-box-f style="line-height: 38px;">
          <template slot="name">{{$t('State')}}</template>
          <template slot="content">
            <el-radio-group
              v-model="form.status"
              size="small"
            >
              <el-radio :label="1">{{$t('Enable')}}</el-radio>
              <el-radio :label="0">{{$t('Disable')}}</el-radio>
            </el-radio-group>
          </template>
        </m-list-box-f>
      </div>
    </template>
  </m-popover>
</template>
<script>
  import mPopover from '@/module/components/popup/popover'
  import mListBoxF from '@/module/components/listBoxF/listBoxF'

  export default {
    name: 'create-user-group',
    data () {
      return {
        form: {
          userGroup: '',
          remark: '',
          userIds: [],
          resourceIds: [],
          status: 1
        },
        options: [
          {
            value: '1',
            label: '柏林1'
          },
          {
            value: '2',
            label: '小小2'
          },
          {
            value: '3',
            label: '小小3'
          }
        ],
      }
    },
    props: {
      item: Object,
    },
    methods: {
      _ok () {
        if (this._verification()) {
          console.log('_ok')
        }
      },
      _verification () {
        // let userGroupLength = this.form.userGroup.length
        // user name
        // if (userGroupLength < 3 || userGroupLength > 39) {
        //   this.$message.warning(`${i18n.$t('User name length is between 3 and 39')}`)
        //   return false
        // }
        // if (!this.form.userGroup.replace(/\s*/g, '')) {
        //   this.$message.warning(`${i18n.$t('Please enter user name')}`)
        //   return false
        // }
        return true
      },
      _submit () {
        this.$refs.popover.spinnerLoading = true
      },
      close () {
        this.$emit('close')
      }
    },
    mounted () {
      if (this.item) {
        console.log('this.item', this.item)

        this.form = Object.assign(this.form, {
          ...this.item,
          userIds: this.item.userIds.split(','),
          resourceIds: this.item.resourceIds.split(','),
        })
      }
    },
    components: { mPopover, mListBoxF }
  }
</script>
